﻿<Window x:Class="SellAvi.Views.WindowProductImport"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        Title="Импорт товаров из Excel" Height="400" Width="550"
        DataContext="{Binding ProductImport, Source={StaticResource Locator}}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/SellAvi;component/Views/Styles/ComfortStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Window.InputBindings>
        <KeyBinding Gesture="Ctrl+V" Command="{Binding PasteDataCommand}" />
    </Window.InputBindings>
    <DockPanel>

        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,10">
            <Label Content="Регион"></Label>
            <ComboBox  Width="120" ItemsSource="{Binding ServiceProxy.GetRegions}" DisplayMemberPath="RegionName" SelectedItem="{Binding ChoosenRegion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            </ComboBox>
            <Label Content="Категория"></Label>
            <ComboBox  Width="120" ItemsSource="{Binding ServiceProxy.GetCategories}" DisplayMemberPath="CategoryName" SelectedItem="{Binding ChoosenCategory}">
            </ComboBox>
            <Label Content="Тип тов-ра"></Label>
            <ComboBox  Width="120" ItemsSource="{Binding TFilteredParameters}" DisplayMemberPath="ParamName" SelectedItem="{Binding ChoosenParameter}">
            </ComboBox>
        </StackPanel>
        <DockPanel DockPanel.Dock="Top" Height="60" LastChildFill="True">
            <Border DockPanel.Dock="Right" Margin="10,0,10,0" CornerRadius="2" BorderThickness="1" AllowDrop="True">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Drop">
                        <command:EventToCommand Command="{Binding DropFileCommand}" PassEventArgsToCommand="True" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Border.Style>
                    <Style TargetType="Border">
                        <Setter Property="BorderBrush" Value="Gray"></Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="BorderBrush" Value="Transparent" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <Border.Background>
                    <ImageBrush Stretch="None" ImageSource="/SellAvi;component/Resources/camera.png" AlignmentY="Center" AlignmentX="Center" Opacity="0.3"/>
                </Border.Background>
                <TextBlock Text="Область перетаскивания фото" AllowDrop="True" TextAlignment="Center" VerticalAlignment="Bottom" Foreground="Gray">
                </TextBlock>
            </Border>
            <!-- * -->
            <Button DockPanel.Dock="Left" Command="{Binding PasteDataCommand}" Margin="10,0,10,0" Background="Transparent" BorderBrush="Gray">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/arrow3_s.png" Width="14"></Image>
                    <TextBlock Margin="5,0,5,0">Вставить из Excel</TextBlock>
                </StackPanel>
            </Button>
        </DockPanel>
        
        <DockPanel Dock="Top" MaxHeight="60">
            <TextBlock Text="{Binding ImportMessage}" TextAlignment="Center" FontSize="10"></TextBlock>
        </DockPanel>
        
        <DockPanel DockPanel.Dock="Bottom" Background="LightGray">
            <Button DockPanel.Dock="Right" Command="{Binding SaveProductsCommand}" >
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/save.png" Width="14"></Image>
                    <TextBlock Margin="5,0,5,0">Сохранить</TextBlock>
                </StackPanel>
            </Button>
            <Button DockPanel.Dock="Right" Command="{Binding RemoveDuplicatesCommand}" IsEnabled="False">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/newwindow.png" Width="14"></Image>
                    <TextBlock Margin="5,0,5,0">Убрать дубликаты</TextBlock>
                </StackPanel>
            </Button>
            <Button DockPanel.Dock="Right" Command="{Binding CleanImportCommand}" >
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/trash.png" Width="14"></Image>
                    <TextBlock Margin="5,0,5,0">Очистить все</TextBlock>
                </StackPanel>
            </Button>
            <!--<ProgressBar DockPanel.Dock="Left" Width="105" Margin="4"/>-->
            <DockPanel></DockPanel>
        </DockPanel>
        <Grid  DockPanel.Dock="Bottom" Background="LightGray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="30"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="30"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Text="Объявлений:"/>
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Ошибочных:"/>
            <!-- TextAlignment="Center" VerticalAlignment="Center"-->
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ImportedLines, Mode=OneWay}"/>
            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ImportedErrors, Mode=OneWay}"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Text="Изображений:"/>
            <TextBox Grid.Row="0" Grid.Column="3" Text="{Binding ImportedImages, Mode=OneWay}"/>
            <TextBlock Grid.Row="1" Grid.Column="2" Text="Изобр. всего:"/>
            <TextBox Grid.Row="1" Grid.Column="3" Text="{Binding ImportedImagesTotal, Mode=OneWay}"/>

        </Grid>

        <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ImportedProducts, IsAsync=True}" CanUserAddRows="False" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray">
            <DataGrid.Columns>
                <DataGridTextColumn Width ="150" Header="Наименование" Binding="{Binding Title}" />
                <DataGridTextColumn Width="*" Header="Подробное описание" Binding="{Binding Description}" />
                <DataGridTextColumn Width ="100" Header="Цена" Binding="{Binding Price}" />
                <DataGridTemplateColumn Header="Фото" Width="40" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image DataContext="{Binding}" Source="{Binding MainProductImage,FallbackValue=/SellAvi;component/Resources/denied.png, UpdateSourceTrigger=PropertyChanged}" Stretch="UniformToFill" MaxHeight="40" HorizontalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</Window>
